package com.icart.repositories;


import com.icart.entities.CuCusttcEntity;
import org.springframework.context.annotation.Scope;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import javax.persistence.EntityManager;

@Repository
@Scope("prototype")
public interface CusttcRepository extends BaseRepository<CuCusttcEntity,Integer> {
    @Transactional
    @Query(nativeQuery = true,value = "insert into cu_custtc (tcoid,custid, tcid, tcname, tccode, tctype, validmonth, totalval, saleprice, presentval, limitchn, remark, stat, usestartdate, useenddate, creattime, creatchn, creator, sourceoid) " +
            "select  ?1,?2,tcid, tcname, tccode, tctype, validmonth, totalval, saleprice, presentval, limitchn, remark, stat,?3,DATE_ADD(?4,INTERVAL validmonth MONTH), creattime, creatchn, creator,?5 " +
            "from mk_discpack where tcid=?6")
    @Modifying(clearAutomatically = true)
    Integer save(Long tcoid,Long custid,String usestartdate,String usestartdate2,String oid,Long tcid);

    //insert into cu_custtc (custid, tcid, tcname, tccode, tctype, validmonth, totalval, saleprice, presentval, limitchn, remark, stat, usestartdate, useenddate, creattime, creatchn, creator )
    //select 19, tcid, tcname, tccode, tctype, validmonth, totalval, saleprice, presentval, limitchn, remark, stat,salestartdate as usestartdate,saleenddate as useenddate, creattime, creatchn, creator
    //from mk_discpack where tcid=133
}
